%include "include/sconst.inc"

global disable_irq
global enable_irq

disable_irq:
    push ecx
    mov ecx, [esp + 8] ;irq

    cli
    mov ah,1
    rol ah,cl
    cmp cl,8
    jae disable_8
disable_0:
    in al, INT_M_MASK
    test al, ah
    jnz disable_already
    or al, ah
    out INT_M_MASK, al
    pop ecx
    mov eax, 1
    ret
disable_8:
    in al, INT_S_MASK
    test al, ah
    jnz disable_already
    or al, ah
    out INT_S_MASK, al
    pop ecx
    mov eax, 1
    ret
disable_already:
    pop ecx
    xor eax, eax
    ret

enable_irq:
    push ecx
    mov ecx, [esp + 8] ;irq
    cli
    mov ah,~1
    rol ah,cl
    cmp cl,8
    jae enable_8
enable_0:
    in al, INT_M_MASK
    and al, ah
    out INT_M_MASK, al
    sti
    pop ecx
    ret
enable_8:
    in al, INT_S_MASK
    and al, ah
    out INT_S_MASK, al
    pop ecx
    sti
    ret